//SituationController.cpp
/*
Situation class
Created by: Taryn Green & Chris Groce
Updated: 10/14/2013
*/

#include <iostream>
//#include "Room.h"
#include "Player.h"
#include "Situation.h"
#include "SituationController.h"

using boost::asio::ip::tcp;


using namespace std;


SituationController::SituationController()
{
	Situation s;
	situation = s;
}
SituationController::SituationController(Graphics *graphicControl, networkI::networkHandler *networkControl)
{
	Situation s;
	situation = s;

//	graphicController = graphicControl;
	networkController = networkControl;
}

void SituationController::acceptGraphics(Graphics *graphicControl)
{
	graphicController = graphicControl;
}

void SituationController::setNetwork(networkI::networkHandler *mHandler)
{
	networkController = mHandler;
}

void SituationController:: turnLeft()
{
	situation.turnPlayerLeft();
}
void SituationController:: turnRight()
{
	situation.turnPlayerRight();
}
void SituationController:: turnDown()
{
	situation.turnPlayerDown();
}
void SituationController:: turnUp()
{
	situation.turnPlayerUp();
}

void SituationController:: advanceLeft()
{
	situation.advancePlayerLeft();
}
void SituationController:: advanceRight()
{
	situation.advancePlayerRight();
}
void SituationController:: advanceDown()
{
	situation.advancePlayerDown();
}
void SituationController:: advanceUp()
{
	situation.advancePlayerUp();
}
void SituationController:: advanceForward()	//Change the speed
{
	situation.advancePlayerForward();
}
void SituationController:: advanceBackward()	//Change the speed
{
	situation.advancePlayerBackward();
}
void SituationController::fire()
{
	situation.shoot();
}


void SituationController:: tick()
{
	//std::cout<<"In tick\n";
	//Calculate new positions
	situation.updatePlayerPositions();
	//Reset speeds
	situation.resetPlayerSpeeds();

	situation.advanceShots();

	//Send updated situation to network and GL
	//GL
	graphicController->draw(situation);
	//Network
	//Send to a network 

	networkController->sendSituation(situation);

	if(networkController->getNeedToReconcile()) {
		//std::cout << "Need to reconcile\n";
		reconcile(networkController->MySituation);
		networkController->setNeedToReconcile(false);
	}

}

void SituationController:: reconcile(Situation newSituation)
{
	situation.setOpponent(newSituation.getPlayer());
	// Need to reconcile bullets, the vector of Shot objects
	// that is a private data member of the Situation class
}

void SituationController:: print()
{
	std::cout << "Player" << std::endl;
	Player p = situation.getPlayer();
	//std::cout << p.getForwardSpeed() << "\t" << p.getHorFacing() << "\t" << p.getUpSpeed() << std::endl;

	std::cout << "Opponent" << std::endl;
	p = situation.getOpponent();
	//std::cout << p.getForwardSpeed() << "\t" << p.getHorFacing() << "\t" << p.getUpSpeed() << std::endl;

}
